var MsgSender = (function(){
    //消息发送接口预处理.
    $.ajaxPrefilter(function(options, originalOptions, jqXHR){    
        var url = options['url'];
        if(url == '/rest/apis/chat/topic'){
            var data = JSON.insure(options['data']);
            var chatGroupEntity = page.chatGroupStore.getItem(data['teid']);
            if(chatGroupEntity.perm.rloc && page.position){ 
                data['la'] = page.position.coords.latitude;
                data['lo'] = page.position.coords.longitude;
                options['data'] = JSON.stringify(data);
            }
        }
        if(url.endsWith('/upload?type=image') || url.endsWith('/upload?type=file')){
            var teid = url.split('chat/').last().split('/').first();
            var chatGroupEntity = page.chatGroupStore.getItem(teid);
            if(chatGroupEntity.perm.rloc && page.position){
                options['url'] = url.addQuery({
                    la : page.position.coords.latitude,
                    lo : page.position.coords.longitude
                });   
            }
        }
    });    
    /**
     * 消息发送器构造函数. 
     * @param {Object} content
     */
    function _MsgSender(content){
        this.user = ujs.util.session.getCurrentUserInfo();
        this.chatPanel = ChatPanel.getActiveChatPanel();
        this.chatGroupID = this.chatPanel.chatGroupEntity['id'];
        this.content = content; 
    } 
    /**
     * 通用发送消息函数.
     * @param {String} type
     * @param {Object} content
     * @param {Function} cb
     */
    _MsgSender.send = function(type, content, cb){
        var msgSenderObj = new window[type.uppercaseFirstChar() + 'MsgSender'](content);
        msgSenderObj.send(function(msg){
            cb && cb(msg);
        });
    };
    
    return _MsgSender;
})();